package o;

import android.annotation.TargetApi;
import android.content.Context;
import android.graphics.SurfaceTexture;
import android.os.Handler;
import android.os.Looper;
import android.view.Surface;
import android.view.SurfaceHolder;
import android.view.SurfaceHolder.Callback;
import android.view.TextureView;
import android.view.TextureView.SurfaceTextureListener;
import androidx.annotation.Nullable;
import com.google.android.exoplayer2.Format;
import com.google.android.exoplayer2.Player.d;
import com.google.android.exoplayer2.Renderer;
import com.google.android.exoplayer2.audio.AudioFocusManager;
import com.google.android.exoplayer2.audio.AudioFocusManager.b;
import com.google.android.exoplayer2.drm.DefaultDrmSessionManager;
import com.google.android.exoplayer2.metadata.Metadata;
import com.google.android.exoplayer2.text.Cue;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.concurrent.CopyOnWriteArraySet;
import o.abx.a;

@TargetApi(16)
public class abu extends aaz implements abc {
    private final CopyOnWriteArraySet<ahh> ʻ;
    private boolean ʻॱ;
    private final CopyOnWriteArraySet<ajn> ʼ;
    @Nullable
    private acz ʼॱ;
    private final CopyOnWriteArraySet<abw> ʽ;
    @Nullable
    private TextureView ʽॱ;
    private int ʾ;
    @Nullable
    private acz ʿ;
    private int ˈ;
    private aby ˉ;
    private final c ˊ;
    private float ˊˊ;
    @Nullable
    private aim ˊˋ;
    private final abx ˊॱ;
    private List<Cue> ˊᐝ;
    private final Handler ˋ;
    private int ˋˊ;
    private boolean ˋˋ;
    @Nullable
    private Format ˋॱ;
    protected final Renderer[] ˎ;
    private final CopyOnWriteArraySet<acf> ˏॱ;
    private final ald ͺ;
    private final abe ॱ;
    private final AudioFocusManager ॱˊ;
    @Nullable
    private Surface ॱˋ;
    @Nullable
    private SurfaceHolder ॱˎ;
    private final CopyOnWriteArraySet<aoc> ॱॱ;
    @Nullable
    private Format ॱᐝ;
    private final CopyOnWriteArraySet<anz> ᐝ;
    private int ᐝॱ;

    final class c implements anz, acf, ajn, ahh, Callback, SurfaceTextureListener, b {
        final /* synthetic */ abu ˋ;

        private c(abu o_abu) {
            this.ˋ = o_abu;
        }

        public void ˏ(acz o_acz) {
            this.ˋ.ʿ = o_acz;
            Iterator it = this.ˋ.ᐝ.iterator();
            while (it.hasNext()) {
                ((anz) it.next()).ˏ(o_acz);
            }
        }

        public void ˎ(String str, long j, long j2) {
            Iterator it = this.ˋ.ᐝ.iterator();
            while (it.hasNext()) {
                ((anz) it.next()).ˎ(str, j, j2);
            }
        }

        public void ˏ(Format format) {
            this.ˋ.ˋॱ = format;
            Iterator it = this.ˋ.ᐝ.iterator();
            while (it.hasNext()) {
                ((anz) it.next()).ˏ(format);
            }
        }

        public void ॱ(int i, long j) {
            Iterator it = this.ˋ.ᐝ.iterator();
            while (it.hasNext()) {
                ((anz) it.next()).ॱ(i, j);
            }
        }

        public void ˏ(int i, int i2, int i3, float f) {
            Iterator it = this.ˋ.ॱॱ.iterator();
            while (it.hasNext()) {
                aoc o_aoc = (aoc) it.next();
                if (!this.ˋ.ᐝ.contains(o_aoc)) {
                    o_aoc.ˏ(i, i2, i3, f);
                }
            }
            it = this.ˋ.ᐝ.iterator();
            while (it.hasNext()) {
                ((anz) it.next()).ˏ(i, i2, i3, f);
            }
        }

        public void ˎ(Surface surface) {
            Iterator it;
            if (this.ˋ.ॱˋ == surface) {
                it = this.ˋ.ॱॱ.iterator();
                while (it.hasNext()) {
                    ((aoc) it.next()).ˋ();
                }
            }
            it = this.ˋ.ᐝ.iterator();
            while (it.hasNext()) {
                ((anz) it.next()).ˎ(surface);
            }
        }

        public void ˋ(acz o_acz) {
            Iterator it = this.ˋ.ᐝ.iterator();
            while (it.hasNext()) {
                ((anz) it.next()).ˋ(o_acz);
            }
            this.ˋ.ˋॱ = null;
            this.ˋ.ʿ = null;
        }

        public void ॱ(acz o_acz) {
            this.ˋ.ʼॱ = o_acz;
            Iterator it = this.ˋ.ˏॱ.iterator();
            while (it.hasNext()) {
                ((acf) it.next()).ॱ(o_acz);
            }
        }

        public void ॱ(int i) {
            if (this.ˋ.ˋˊ != i) {
                this.ˋ.ˋˊ = i;
                Iterator it = this.ˋ.ʽ.iterator();
                while (it.hasNext()) {
                    abw o_abw = (abw) it.next();
                    if (!this.ˋ.ˏॱ.contains(o_abw)) {
                        o_abw.ॱ(i);
                    }
                }
                it = this.ˋ.ˏॱ.iterator();
                while (it.hasNext()) {
                    ((acf) it.next()).ॱ(i);
                }
            }
        }

        public void ॱ(String str, long j, long j2) {
            Iterator it = this.ˋ.ˏॱ.iterator();
            while (it.hasNext()) {
                ((acf) it.next()).ॱ(str, j, j2);
            }
        }

        public void ˎ(Format format) {
            this.ˋ.ॱᐝ = format;
            Iterator it = this.ˋ.ˏॱ.iterator();
            while (it.hasNext()) {
                ((acf) it.next()).ˎ(format);
            }
        }

        public void ˏ(int i, long j, long j2) {
            Iterator it = this.ˋ.ˏॱ.iterator();
            while (it.hasNext()) {
                ((acf) it.next()).ˏ(i, j, j2);
            }
        }

        public void ˎ(acz o_acz) {
            Iterator it = this.ˋ.ˏॱ.iterator();
            while (it.hasNext()) {
                ((acf) it.next()).ˎ(o_acz);
            }
            this.ˋ.ॱᐝ = null;
            this.ˋ.ʼॱ = null;
            this.ˋ.ˋˊ = 0;
        }

        public void ˎ(List<Cue> list) {
            this.ˋ.ˊᐝ = list;
            Iterator it = this.ˋ.ʼ.iterator();
            while (it.hasNext()) {
                ((ajn) it.next()).ˎ(list);
            }
        }

        public void ˋ(Metadata metadata) {
            Iterator it = this.ˋ.ʻ.iterator();
            while (it.hasNext()) {
                ((ahh) it.next()).ˋ(metadata);
            }
        }

        public void surfaceCreated(SurfaceHolder surfaceHolder) {
            this.ˋ.ˎ(surfaceHolder.getSurface(), false);
        }

        public void surfaceChanged(SurfaceHolder surfaceHolder, int i, int i2, int i3) {
            this.ˋ.ˎ(i2, i3);
        }

        public void surfaceDestroyed(SurfaceHolder surfaceHolder) {
            this.ˋ.ˎ(null, false);
            this.ˋ.ˎ(0, 0);
        }

        public void onSurfaceTextureAvailable(SurfaceTexture surfaceTexture, int i, int i2) {
            this.ˋ.ˎ(new Surface(surfaceTexture), true);
            this.ˋ.ˎ(i, i2);
        }

        public void onSurfaceTextureSizeChanged(SurfaceTexture surfaceTexture, int i, int i2) {
            this.ˋ.ˎ(i, i2);
        }

        public boolean onSurfaceTextureDestroyed(SurfaceTexture surfaceTexture) {
            this.ˋ.ˎ(null, true);
            this.ˋ.ˎ(0, 0);
            return true;
        }

        public void onSurfaceTextureUpdated(SurfaceTexture surfaceTexture) {
        }

        public void ॱ(float f) {
            this.ˋ.ˏॱ();
        }

        public void ˏ(int i) {
            this.ˋ.ˏ(this.ˋ.ˎ(), i);
        }
    }

    protected abu(Context context, abt o_abt, alb o_alb, abi o_abi, @Nullable adf<adn> o_adf_o_adn, ald o_ald, a aVar, Looper looper) {
        this(context, o_abt, o_alb, o_abi, o_adf_o_adn, o_ald, aVar, ams.ॱ, looper);
    }

    protected abu(Context context, abt o_abt, alb o_alb, abi o_abi, @Nullable adf<adn> o_adf_o_adn, ald o_ald, a aVar, ams o_ams, Looper looper) {
        this.ͺ = o_ald;
        this.ˊ = new c();
        this.ॱॱ = new CopyOnWriteArraySet();
        this.ʽ = new CopyOnWriteArraySet();
        this.ʼ = new CopyOnWriteArraySet();
        this.ʻ = new CopyOnWriteArraySet();
        this.ᐝ = new CopyOnWriteArraySet();
        this.ˏॱ = new CopyOnWriteArraySet();
        this.ˋ = new Handler(looper);
        this.ˎ = o_abt.ˎ(this.ˋ, this.ˊ, this.ˊ, this.ˊ, this.ˊ, o_adf_o_adn);
        this.ˊˊ = 1.0f;
        this.ˋˊ = 0;
        this.ˉ = aby.ˏ;
        this.ᐝॱ = 1;
        this.ˊᐝ = Collections.emptyList();
        this.ॱ = new abe(this.ˎ, o_alb, o_abi, o_ald, o_ams, looper);
        this.ˊॱ = aVar.ˊ(this.ॱ, o_ams);
        ˏ(this.ˊॱ);
        this.ᐝ.add(this.ˊॱ);
        this.ॱॱ.add(this.ˊॱ);
        this.ˏॱ.add(this.ˊॱ);
        this.ʽ.add(this.ˊॱ);
        ˏ(this.ˊॱ);
        o_ald.ˏ(this.ˋ, this.ˊॱ);
        if (o_adf_o_adn instanceof DefaultDrmSessionManager) {
            ((DefaultDrmSessionManager) o_adf_o_adn).ॱ(this.ˋ, this.ˊॱ);
        }
        this.ॱˊ = new AudioFocusManager(context, this.ˊ);
    }

    public void ˋ(@Nullable Surface surface) {
        int i = 0;
        ॱᐝ();
        ʻ();
        ˎ(surface, false);
        if (surface != null) {
            i = -1;
        }
        ˎ(i, i);
    }

    public void ॱ(float f) {
        ॱᐝ();
        float ˋ = anr.ˋ(f, 0.0f, 1.0f);
        if (this.ˊˊ != ˋ) {
            this.ˊˊ = ˋ;
            ˏॱ();
            Iterator it = this.ʽ.iterator();
            while (it.hasNext()) {
                ((abw) it.next()).ˎ(ˋ);
            }
        }
    }

    public void ˏ(aoc o_aoc) {
        this.ॱॱ.add(o_aoc);
    }

    public void ॱ(aoc o_aoc) {
        this.ॱॱ.remove(o_aoc);
    }

    public void ˏ(ahh o_ahh) {
        this.ʻ.add(o_ahh);
    }

    public Looper ˊ() {
        return this.ॱ.ˎ();
    }

    public void ˏ(d dVar) {
        ॱᐝ();
        this.ॱ.ॱ(dVar);
    }

    public void ॱ(d dVar) {
        ॱᐝ();
        this.ॱ.ˏ(dVar);
    }

    public int ˏ() {
        ॱᐝ();
        return this.ॱ.ˏ();
    }

    public void ˋ(aim o_aim) {
        ॱ(o_aim, true, true);
    }

    public void ॱ(aim o_aim, boolean z, boolean z2) {
        ॱᐝ();
        if (this.ˊˋ != null) {
            this.ˊˋ.ˏ(this.ˊॱ);
            this.ˊॱ.ॱ();
        }
        this.ˊˋ = o_aim;
        o_aim.ˏ(this.ˋ, this.ˊॱ);
        ˏ(ˎ(), this.ॱˊ.ॱ(ˎ()));
        this.ॱ.ॱ(o_aim, z, z2);
    }

    public void ˋ(boolean z) {
        ॱᐝ();
        ˏ(z, this.ॱˊ.ˏ(z, ˏ()));
    }

    public boolean ˎ() {
        ॱᐝ();
        return this.ॱ.ˊ();
    }

    public void ˎ(int i) {
        ॱᐝ();
        this.ॱ.ॱ(i);
    }

    public void ˏ(int i, long j) {
        ॱᐝ();
        this.ˊॱ.ˎ();
        this.ॱ.ˏ(i, j);
    }

    public void ˏ(@Nullable abv o_abv) {
        ॱᐝ();
        this.ॱ.ˊ(o_abv);
    }

    public void ˎ(boolean z) {
        ॱᐝ();
        this.ॱ.ˊ(z);
        if (this.ˊˋ != null) {
            this.ˊˋ.ˏ(this.ˊॱ);
            this.ˊॱ.ॱ();
            if (z) {
                this.ˊˋ = null;
            }
        }
        this.ॱˊ.ˋ();
        this.ˊᐝ = Collections.emptyList();
    }

    public void ʽ() {
        this.ॱˊ.ˋ();
        this.ॱ.ʻ();
        ʻ();
        if (this.ॱˋ != null) {
            if (this.ʻॱ) {
                this.ॱˋ.release();
            }
            this.ॱˋ = null;
        }
        if (this.ˊˋ != null) {
            this.ˊˋ.ˏ(this.ˊॱ);
            this.ˊˋ = null;
        }
        this.ͺ.ॱ(this.ˊॱ);
        this.ˊᐝ = Collections.emptyList();
    }

    public abr ᐝॱ() {
        ॱᐝ();
        return this.ॱ.ᐝॱ();
    }

    public int ॱॱ() {
        ॱᐝ();
        return this.ॱ.ॱॱ();
    }

    public long ᐝ() {
        ॱᐝ();
        return this.ॱ.ᐝ();
    }

    public long ʼ() {
        ॱᐝ();
        return this.ॱ.ʼ();
    }

    public long ॱˊ() {
        ॱᐝ();
        return this.ॱ.ॱˊ();
    }

    public long ˊॱ() {
        ॱᐝ();
        return this.ॱ.ˊॱ();
    }

    public int ͺ() {
        ॱᐝ();
        return this.ॱ.ͺ();
    }

    public int ˋॱ() {
        ॱᐝ();
        return this.ॱ.ˋॱ();
    }

    public long ॱˎ() {
        ॱᐝ();
        return this.ॱ.ॱˎ();
    }

    private void ʻ() {
        if (this.ʽॱ != null) {
            if (this.ʽॱ.getSurfaceTextureListener() != this.ˊ) {
                amz.ˏ("SimpleExoPlayer", "SurfaceTextureListener already unset or replaced.");
            } else {
                this.ʽॱ.setSurfaceTextureListener(null);
            }
            this.ʽॱ = null;
        }
        if (this.ॱˎ != null) {
            this.ॱˎ.removeCallback(this.ˊ);
            this.ॱˎ = null;
        }
    }

    private void ˎ(@Nullable Surface surface, boolean z) {
        List<abn> arrayList = new ArrayList();
        for (o.abn.c cVar : this.ˎ) {
            if (cVar.f_() == 2) {
                arrayList.add(this.ॱ.ॱ(cVar).ॱ(1).ˏ(surface).ॱॱ());
            }
        }
        if (!(this.ॱˋ == null || this.ॱˋ == surface)) {
            try {
                for (abn ˏॱ : arrayList) {
                    ˏॱ.ˏॱ();
                }
            } catch (InterruptedException e) {
                Thread.currentThread().interrupt();
            }
            if (this.ʻॱ) {
                this.ॱˋ.release();
            }
        }
        this.ॱˋ = surface;
        this.ʻॱ = z;
    }

    private void ˎ(int i, int i2) {
        if (i != this.ʾ || i2 != this.ˈ) {
            this.ʾ = i;
            this.ˈ = i2;
            Iterator it = this.ॱॱ.iterator();
            while (it.hasNext()) {
                ((aoc) it.next()).ˎ(i, i2);
            }
        }
    }

    private void ˏॱ() {
        float ˊ = this.ॱˊ.ˊ() * this.ˊˊ;
        for (o.abn.c cVar : this.ˎ) {
            if (cVar.f_() == 1) {
                this.ॱ.ॱ(cVar).ॱ(2).ˏ(Float.valueOf(ˊ)).ॱॱ();
            }
        }
    }

    private void ˏ(boolean z, int i) {
        boolean z2;
        boolean z3 = true;
        abe o_abe = this.ॱ;
        if (!z || i == -1) {
            z2 = false;
        } else {
            z2 = true;
        }
        if (i == 1) {
            z3 = false;
        }
        o_abe.ˊ(z2, z3);
    }

    private void ॱᐝ() {
        if (Looper.myLooper() != ˊ()) {
            amz.ˋ("SimpleExoPlayer", "Player is accessed on the wrong thread. See https://google.github.io/ExoPlayer/faqs.html#what-do-player-is-accessed-on-the-wrong-thread-warnings-mean", this.ˋˋ ? null : new IllegalStateException());
            this.ˋˋ = true;
        }
    }
}
